package cn.com.scan.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.com.scan.R;
import cn.com.scan.config.Config;
import cn.com.scan.entity.ApplicationItem;
import cn.com.scan.entity.ExportItem;

/**
 * Created by My on 2016/1/1.
 */
public class ExportItemAdapter extends BaseAdapter{
    Context context;
    List<ExportItem> objects=new ArrayList<ExportItem>();
    public ExportItemAdapter(Context context) {
        this.context=context;
        this.objects=objects;
    }
    public  void  setList(List<ExportItem> objects){
        if(objects!=null){
            this.objects.clear();
            this.objects.addAll(objects);
        }else{
            this.objects.clear();
        }
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ExportItem exportItem=objects.get(position);
        Config.LogI("position:"+position);
        ViewHolder viewHolder;
        if(convertView==null){
           viewHolder=new  ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.import_storage_item,parent,false);
            viewHolder.name=(TextView)convertView.findViewById(R.id.name);
            viewHolder.name.setTextColor(Color.parseColor("#434343"));
            viewHolder.standard=(TextView)convertView.findViewById(R.id.standard);
            viewHolder.standard.setTextColor(Color.parseColor("#434343"));
            viewHolder.hasnum=(TextView)convertView.findViewById(R.id.hasnum);
            viewHolder.hasnum.setTextColor(Color.parseColor("#434343"));
            viewHolder.actualnum=(TextView)convertView.findViewById(R.id.actualnum);
             viewHolder.actualnum.setTextColor(Color.parseColor("#434343"));
            viewHolder.time_num=(TextView)convertView.findViewById(R.id.time_num);
            viewHolder.time_num.setTextColor(Color.parseColor("#434343"));
            viewHolder.batch_num=(TextView)convertView.findViewById(R.id.batch_num);
            viewHolder.batch_num.setTextColor(Color.parseColor("#434343"));
            viewHolder.line=(View)convertView.findViewById(R.id.view_line);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder)convertView.getTag();
        }
        viewHolder.line.setVisibility(View.GONE);
        viewHolder.hasnum.setVisibility(View.GONE);
        viewHolder.name.setText(exportItem.getEXP_NAME());
        viewHolder.standard.setText(exportItem.getEXP_SPEC());
//        viewHolder.hasnum.setText(exportItem.getQUANTITY() + "");
        viewHolder.actualnum.setText(exportItem.getQUANTITY());
        viewHolder.time_num.setText(exportItem.getEXPIRE_DATE());
        viewHolder.batch_num.setText(exportItem.getBATCH_NO());

        return convertView;
    }
    class ViewHolder{
        TextView name,standard,hasnum,actualnum,time_num,batch_num;
        View  line;
    }
}
